﻿using ConsoleApp2.Impl;
using ConsoleApp2.Service;
using System.Collections.Generic;

namespace ConsoleApp2.Models;

public class LocalRole
{
    public static List<Role> Roles { get; set; }

    public LocalRole()
    {
        LoadUsers();
    }

    public static List<Role> LoadUsers()
    {
        if (Roles == null)
        {
            Roles = new List<Role>();
            InitializeRoles(); 
        }
        return Roles;
    }

    private static void InitializeRoles() 
    {
        PermissionService permissionService = new PermissionServiceImpl();
        List<Permission> allPermissions = permissionService.GetAllPermissions();
        
        Role adminRole = new Role()
        {
            RoleName = ConsoleApp2.Enum.RoleName.管理人员,
            CreateTime = System.DateTime.Now,
            UpdateTime = System.DateTime.Now,
            IsDeleted = false,
            Permissions = new List<Permission>(allPermissions) 
        };
        Roles.Add(adminRole);
        
        Role userRole = new Role()
        {
            RoleName = ConsoleApp2.Enum.RoleName.普通用户,
            CreateTime = System.DateTime.Now,
            UpdateTime = System.DateTime.Now,
            IsDeleted = false,
            Permissions = new List<Permission>() 
        };
        Roles.Add(userRole);
    }
}